package com.newtouch.bxzs.database.synchronize.quartz;

import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import org.quartz.CronScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


/**
 * CrowTriggerDemo:
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/25 16:47</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class QuartzTrigger {

    @Value("${jobTime.month}")
    private String month;

    @Value("${jobTime.day}")
    private String day;

    @Autowired
    RedisUtils redisUtils;

    public Trigger synchronizeOrganTrigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("synchronizeOrganTrigger","Group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(month))
                .build();
    }
    public Trigger synchronizeUserTrigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("synchronizeUserTrigger","Group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(month))
                .build();
    }
    public Trigger synchronizeCustomerTrigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("synchronizeCustomerTrigger","Group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(month))
                .build();
    }

    public Trigger synchronizeAchievementTrigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("synchronizeAchievementTrigger","Group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(month))
                .build();
    }

    public Trigger synchronizeIncomeTrigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("synchronizeIncomeTrigger","Group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(month))
                .build();
    }

    public Trigger synchronizeProductTrigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("synchronizeProductTrigger","Group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(month))
                .build();
    }

    public Trigger updateStatusTrigger(){
        return TriggerBuilder.newTrigger()
                .withIdentity("updateStatusTrigger","updateStatusTrigger")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(day))
                .build();
    }
    public Trigger remainToUpgradeTrigger(){
        String result = redisUtils.get(SystemParamsEnum.MESSAGE_NOTIFICATION_FREQUENCY.getCode());
        String min = "0 0/"+result+" * * * ? ";
        return TriggerBuilder.newTrigger()
                .withIdentity("remainToUpgradeTrigger","remainToUpgradeTrigger")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(min))
                .build();
    }


}
